//09:15-15:00
//18:50-20:10
// var timeSlots=[
//   {
//       start:'09:15'
//     ,end:'15:00'
//   }
//   ,{
//     start:'18:50'
//     ,end:'20:10'
//   }
// ];
function strToTime(timeSlot) {
  var _timeSlot = timeSlot.split(':');
  var timeH = parseInt(_timeSlot[0]);
  var timeM = parseInt(_timeSlot[1]);
  var _time = timeH * 60 + timeM;
  return _time;
}

function timeControl(timeSlots, week, funIn, funOut) {
  //星期判断
  var today = new Date().getDay();
  if (week === undefined) {
    if (today === 0 || today === 6) {
      return;
    }
  } else if (week !== today) {
    return;
  }

  var _now = new Date();
  var now = _now.getHours() * 60 + _now.getMinutes();
  //var now =17*60+10;
  var gaps = timeSlots.length * 2 + 1;
  var points = [];
  timeSlots.forEach(function (timeSlot) {
    points.push(strToTime(timeSlot.start));
    points.push(strToTime(timeSlot.end));
  });

  //console.log(now);
  //console.log(points);
  points.every(function (time, index) {
    if (now < time) {
      //console.log('every',index);
      var fun = null;
      if(index%2==1){
        funIn();
        //console.log('funIn')
      }
      for (var i = index; i < gaps-1; i++) {
        fun = i % 2 == 1 ? funOut : funIn;

        //console.log(i,points[i] - now+"minutes",fun);

        setTimeout(fun, (points[i] - now)*1000*5);
      }
      return false
    }else{
      return true;
    }
  })
}

timeControl(
    [
      {
        start: '17:04'
        , end: '17:06'
      }
      , {
      start: '17:08'
      , end: '17:10'
    }
    ]
    , undefined
    , function () {
      console.log('in')
    }
    , function () {
      console.log('out')
    });